package yc.bluetooth.libvoice.util;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;

/**
 * 作者：yeqianyun on 2020/2/13 16:30
 * 邮箱：1612706976@qq.com
 */
public class HandlerUtil {

    /**
     * Handler发送消息 —— 无参
     * @param handler  Handler对象
     * @param what 标记
     */
    public static void sendEmptyMsg(Handler handler,int what){
        handler.sendEmptyMessage(what);
    }

    /**
     * Handler发送消息 —— 无参
     * @param handler  Handler对象
     * @param what 标记
     * @param delayMillis  延时时长
     */
    public static void sendEmptyMsgDelayed(Handler handler,int what,long delayMillis){
        handler.sendEmptyMessageDelayed(what,delayMillis);
    }

    /**
     * Handler发送消息 —— 一参
     * @param handler  Handler对象
     * @param what 标记
     * @param ob 参数
     */
    public static void sendMsg(Handler handler,int what, Object ob){
        Message message = new Message();
        message.what = what;
        message.obj = ob;
        handler.sendMessage(message);
    }

    public static void sendMsg(Handler handler, int what, Bundle bundle){
        Message message = new Message();
        message.what = what;
        message.setData(bundle);
        handler.sendMessage(message);
    }


    /**
     * Handler发送消息 延时 —— 一参
     * @param handler  Handler对象
     * @param what 标记
     * @param ob 参数
     * @param delayMillis  延时时长
     */
    private void sendMsgDelayed(Handler handler,int what,Object ob,long delayMillis){
        Message message = new Message();
        message.what = what;
        message.obj = ob;
        handler.sendMessageDelayed(message,delayMillis);
    }
}
